// Place your application-specific JavaScript functions and classes here

function funTabColumn(emID, nav, con, cur){
    this.elem = $('#' + emID + '_tabColumn');
    this.nav = nav ? this.elem.find('.' + nav + ' li') : this.elem.find('.nav li');
    this.a = nav ? this.elem.find('.' + nav + ' a') : this.elem.find('.nav a');
    this.span = nav ? this.elem.find('.' + nav + ' span') : this.elem.find('.nav span');
    this.con = con ? this.elem.find('.' + con) : this.elem.find('.con');
    this.more = this.elem.find('.m');
    this.cur = cur ? cur : 'cur';
	this.save = 0;
}

funTabColumn.prototype = {
    constructor: funTabColumn,
    init: function(){
        var that = this;
		for(var i=0; i<that.nav.length; i++){
			if(that.nav.eq(i).hasClass('cur'))
            {
                that.save = i;
                that.span.eq(i).show();
            }
		}
		
		if(typeof(HTMLElement)!="undefined") {   
		      HTMLElement.prototype.contains=function(obj){
			   	  while(obj!=null&&typeof(obj.tagName)!='undefind'){
						if(obj==this)  return true;   
             			obj=obj.parentNode;
				  }
		          return false;   
		      };
		}

        if(that.a)
        {
            that.a.each(function(i){
                $(this).hover(function(){
                    that.showA(i);
                })
            })
        }
        else
        {
            that.nav.each(function(i){
                $(this).hover(function(){
                    that.show(i);
                })
            })
        }

        
		
		that.elem.mouseout(function(theEvent){
			var t = that.elem[0];
			if (theEvent){
                var browser=navigator.userAgent;
                if (browser.indexOf("Gecko")>0){
                    if (t.contains(theEvent.relatedTarget)) {
                        return;
                        } 
                  } 
                  if (browser.indexOf("MSIE")>0){
                       if (t.contains(event.toElement)) {
                             return;
                       }
                   }
             }
             if(that.a)
            {
			    that.showA(that.save);
            }
            else
            {
                that.show(that.save);
            }
		})
    },
    show: function(i){
        var that = this;
        that.index = i;
        that.nav.removeClass(that.cur);
        that.nav.eq(i).addClass(that.cur);
            that.con.addClass('dsn');
            that.con.eq(i).removeClass('dsn');

        if (that.more.length > 1) {
            that.more.hide();
            that.more.eq(i).show();
        }
        
        
    },

    showA: function(i){
        var that = this;
        that.index = i;
        that.span.removeClass(that.cur);
        that.span.eq(i).addClass(that.cur);
            that.con.addClass('dsn');
            that.con.eq(i).removeClass('dsn');

        if (that.span.length > 1) {
            that.span.hide();
            that.span.eq(i).show();
        }
    }

}
